home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Utilities Professional 1-1500
/
Utilities Professional 1-1500 (1994)(WPD)[!].iso
/
12511500
/
var1459.dms
/
var1459.adf
/
Fonts
/
Example3.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-28
|
7KB
|
207 lines
/***********************************************************/
/* */
/* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
/* ------------------------------- ------------------ */
/* */
/* Book: ACM Graphics Amiga C Club */
/* Chapter: Fonts Tulevagen 22 */
/* File: Example3.c 181 41 LIDINGO */
/* Author: Anders Bjerin SWEDEN */
/* Date: 92-04-28 */
/* Version: 1.00 */
/* */
/* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
/* */
/* Registered members may use this program freely in their */
/* own commercial/noncommercial programs/articles. */
/* */
/***********************************************************/
/* This example demonstrates how to open a disk font (Opal, 12) */
/* and prints some characters with the new font in a window. Note! */
/* The font "Opal" must exist in the systems FONT: directory or */
/* you will receive an error message! */
#include <intuition/intuitionbase.h>
struct Intuition *IntuitionBase; /* Running under Intuition. */
struct GfxBase *GfxBase; /* Move() and Text(). */
struct Library *DiskfontBase; /* OpenDiskFont() etc. */
/* NOTE! If you want to use the functions OpenDiskFont() or */
/* AvailFonts() you have to open the Diskfont Library! */
/* The new font's attributes: */
struct TextAttr my_font_attr=
{
"opal.font", /* Name of the font. */
12, /* Height (in pixels) */
FS_NORMAL, /* Style */
FPF_DISKFONT /* Exist on Disk. */
};
/* Pointer to our new font: */
struct TextFont *my_font;
/* Declare a pointer to a Window structure: */
struct Window *my_window;
/* Declare and initialize your NewWindow structure: */
struct NewWindow my_new_window=
{
0, /* LeftEdge x position of the window. */
12, /* TopEdge y positio of the window. */
640, /* Width 640 pixels wide. */
100, /* Height 100 lines high. */
0, /* DetailPen Text should be drawn with colour reg. 0 */
1, /* BlockPen Blocks should be drawn with colour reg. 1 */
CLOSEWINDOW, /* IDCMPFlags The window will give us a message if the */
/* user has selected the Close window gad. */
SMART_REFRESH| /* Flags Intuition should refresh the window. */
WINDOWCLOSE| /* Close Gadget. */
WINDOWDRAG| /* Drag gadget. */
WINDOWDEPTH| /* Depth arrange Gadgets. */
ACTIVATE, /* The window should be Active when opened. */
NULL, /* FirstGadget No Custom gadgets. */
NULL, /* CheckMark Use Intuition's default CheckMark. */
"Wow! This is a disk font!", /* Title Title of the window. */
NULL, /* Screen Connected to the Workbench Screen. */
NULL, /* BitMap No Custom BitMap. */
0, /* MinWidth No sizing gadget. */
0, /* MinHeight -"- */
0, /* MaxWidth -"- */
0, /* MaxHeight -"- */
WBENCHSCREEN /* Type Connected to the Workbench Screen. */
};
void main();
void clean_up();
void main()
{
BOOL close_me; /* Used in the loop. */
ULONG class; /* IDCMP flag. */
struct IntuiMessage *my_message; /* IntuiMessage structure. */
/* Open the necessary libraries: */
IntuitionBase = (struct IntuitionBase *)
OpenLibrary( "intuition.library", 0 );
if( !IntuitionBase )
clean_up( "Could not open Intuition library!" );
GfxBase = (struct GfxBase *)
OpenLibrary( "graphics.library", 0 );
if( !GfxBase )
clean_up( "Could not open Graphics library!" );
DiskfontBase = (struct DiskfontBase *)
OpenLibrary( "diskfont.library", 0 );
if( !DiskfontBase )
clean_up( "Could not open Diskfont library!" );
/* Open a window in which we will display the new font: */
my_window = (struct Window *) OpenWindow( &my_new_window );
/* Have we opened the window succesfully? */
if(my_window == NULL)
clean_up( "Could not open the window!" );
/* Set colour and draw mode: */
SetAPen( my_window->RPort, 1 );
SetDrMd( my_window->RPort, JAM1 );
/* Try to open a disk font: */
my_font = (struct TextFont *)
OpenDiskFont( &my_font_attr );
/* Have we opened the font successfully? */
if( !my_font )
clean_up( "Could not open the font!" );
/* Change the window's default font: */
SetFont( my_window->RPort, my_font );
/* Position the cursor, and print some characters: */
Move( my_window->RPort, 5, 35 );
Text( my_window->RPort, "ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890", 37 );
Move( my_window->RPort, 5, 50 );
Text( my_window->RPort, "abcdefghijklmnopqrstuvwxyz !@#$%^&*()", 37 );
Move( my_window->RPort, 5, 65 );
Text( my_window->RPort, "OOOOOOOOOO", 10 );
Move( my_window->RPort, 5, 80 );
Text( my_window->RPort, "IIIIIIIIII", 10 );
/* NOTE! Opal is a proportional font as you can see when you run the */
/* this example. The line with O:s will be wider than the line of I:s */
/* even when there are exactly the same amount of characters on each */
/* line. */
/* Wait until the user closes the window: */
close_me = FALSE;
while( close_me == FALSE )
{
/* Wait until we have recieved a message: */
Wait( 1 << my_window->UserPort->mp_SigBit );
/* Collect the message: */
while( (my_message = (struct IntuiMessage *) GetMsg( my_window->UserPort )) )
{
/* After we have collected the message we can read it, and save any */
/* important values which we maybe want to check later: */
class = my_message->Class;
/* After we have read it we reply as fast as possible: */
/* REMEMBER! Do never try to read a message after you have replied! */
/* Some other process has maybe changed it. */
ReplyMsg( my_message );
/* Check which IDCMP flag was sent: */
if( class == CLOSEWINDOW )
close_me=TRUE; /* The user selected the Close window gadget! */
}
}
clean_up( "The End" );
}
void clean_up( message )
STRPTR message;
{
if( my_window )
CloseWindow( my_window );
if( my_font )
CloseFont( my_font );
if( DiskfontBase )
CloseLibrary( DiskfontBase );
if( GfxBase )
CloseLibrary( GfxBase );
if( IntuitionBase )
CloseLibrary( IntuitionBase );
printf( "%s\n", message );
exit();
}